class test(object):
    def __init__(self,name):
        self.name=name
        self.x=802
    def test(self):
        print 'test print'
a=test('zhangsan')
print getattr(a,'name','test')
#zhangsan
print getattr(a,'score','test')
#test
print getattr(a,'test','haha')
#<bound method test.test of <__main__.test object at 0x02628910>>
print getattr(a,'test1','haha')
#haha
print getattr(a,'test1')
#Error
hasattr(a,'x')
#True
a.x
#802
setattr(a,'y',801)
hasattr(a,'y')
#True
getattr(a,'y')
#801
